home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / c / c_os3_dt402.lha / c_dt / dt_source / LibInit.c < prev    next >
C/C++ Source or Header  |  1996-09-05  |  4KB  |  139 lines

  1. /*
  2. **      $VER: LibInit.c 40.2 (5.9.96)
  3. **
  4. **      Library initializers and functions to be called by StartUp.c
  5. **
  6. **      (C) Copyright 1996 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <exec/libraries.h>
  13. #include <exec/execbase.h>
  14. #include <exec/resident.h>
  15. #include <exec/initializers.h>
  16. #include <datatypes/pictureclass.h>
  17.  
  18. #include <proto/exec.h>
  19. #include <proto/intuition.h>
  20. #include <proto/datatypes.h>
  21.  
  22. #include <class/classbase.h>
  23. #include "libfuncs.h"
  24.  
  25.  
  26. ULONG __saveds __stdargs L_OpenLibs(void);
  27. void  __saveds __stdargs L_CloseLibs(void);
  28.  
  29. extern struct ClassBase *ClassBase;
  30.  
  31.  
  32. struct ExecBase      *SysBase        = NULL;
  33. struct DosLibrary    *DOSBase        = NULL;
  34. struct IntuitionBase *IntuitionBase  = NULL;
  35. struct GfxBase       *GfxBase        = NULL;
  36. struct Library       *UtilityBase    = NULL;
  37. struct Library       *DataTypesBase  = NULL;
  38. struct Library       *SuperClassBase = NULL;
  39. struct Library       *IFFParseBase   = NULL;
  40.  
  41.  
  42. #define VERSION  40
  43. #define REVISION 2
  44.  
  45. char __aligned ExLibName [] = "cPGM.datatype";
  46. char __aligned ExLibID   [] = "cPGM 40.2 (5.9.96)";
  47. char __aligned Copyright [] = "(C)opyright 1996 by Andreas R. Kleinert. All rights reserved.";
  48.  
  49. extern ULONG InitTab[];
  50.  
  51. extern APTR EndResident; /* below */
  52.  
  53. struct Resident __aligned ROMTag =
  54. {
  55.  RTC_MATCHWORD,
  56.  &ROMTag,
  57.  &EndResident,
  58.  RTF_AUTOINIT,
  59.  VERSION,
  60.  NT_LIBRARY,
  61.  REVISION,
  62.  &ExLibName[0],
  63.  &ExLibID[0],
  64.  &InitTab[0]
  65. };
  66.  
  67. APTR EndResident;
  68.  
  69. struct MyDataInit
  70. {
  71.  UWORD ainit1; UWORD binit1; UWORD ln_type;
  72.  UBYTE ainit2; UBYTE binit2; ULONG ln_name2;
  73.  UWORD ainit3; UWORD binit3; UWORD lib_flags;
  74.  UWORD ainit4; UWORD binit4; UWORD lib_version;
  75.  UWORD ainit5; UWORD binit5; UWORD lib_revision;
  76.  UBYTE ainit6; UBYTE binit6; ULONG lib_idstring2;
  77.  ULONG end;
  78. } DataTab =
  79. {
  80.  INITBYTE(OFFSET(Node,         ln_Type),      NT_LIBRARY),
  81.  0x80, (UBYTE) OFFSET(Node,    ln_Name),      (ULONG) &ExLibName[0],
  82.  INITBYTE(OFFSET(Library,      lib_Flags),    LIBF_SUMUSED|LIBF_CHANGED),
  83.  INITWORD(OFFSET(Library,      lib_Version),  VERSION),
  84.  INITWORD(OFFSET(Library,      lib_Revision), REVISION),
  85.  0x80, (UBYTE) OFFSET(Library, lib_IdString), (ULONG) &ExLibID[0],
  86.  (ULONG) 0
  87. };
  88.  
  89. ULONG __saveds __stdargs L_OpenLibs(void)
  90. {
  91.  SysBase = (*((struct ExecBase **) 4));
  92.  
  93.  DOSBase = (APTR) OpenLibrary("dos.library", 39);
  94.  if(!DOSBase) return(FALSE);
  95.  
  96.  IntuitionBase = (APTR) OpenLibrary("intuition.library", 39);
  97.  if(!IntuitionBase) return(FALSE);
  98.  
  99.  GfxBase = (APTR) OpenLibrary("graphics.library", 39);
  100.  if(!GfxBase) return(FALSE);
  101.  
  102.  UtilityBase = (APTR) OpenLibrary("utility.library", 39);
  103.  if(!UtilityBase) return(FALSE);
  104.  
  105.  DataTypesBase = (APTR) OpenLibrary("datatypes.library", 39);
  106.  if(!DataTypesBase) return(FALSE);
  107.  
  108.  SuperClassBase = (APTR) OpenLibrary("datatypes/picture.datatype", 39);
  109.  if(!SuperClassBase) return(FALSE);
  110.  
  111.  IFFParseBase = (APTR) OpenLibrary("iffparse.library", 37);
  112.  if(!IFFParseBase) return(FALSE);
  113.  
  114.  ClassBase->cb_DOSBase        = (APTR) DOSBase;
  115.  ClassBase->cb_IntuitionBase  = (APTR) IntuitionBase;
  116.  ClassBase->cb_GfxBase        = (APTR) GfxBase;
  117.  ClassBase->cb_UtilityBase    = (APTR) UtilityBase;
  118.  ClassBase->cb_DataTypesBase  = (APTR) DataTypesBase;
  119.  ClassBase->cb_SuperClassBase = (APTR) SuperClassBase;
  120.  ClassBase->cb_IFFParseBase   = (APTR) IFFParseBase;
  121.  
  122.  if(ClassBase->cb_Class = initClass(ClassBase)) return(TRUE);
  123.  
  124.  return(FALSE);
  125. }
  126.  
  127. void __saveds __stdargs L_CloseLibs(void)
  128. {
  129.  if(ClassBase->cb_Class) FreeClass(ClassBase->cb_Class);
  130.  
  131.  if(IFFParseBase)   CloseLibrary((APTR) IFFParseBase);
  132.  if(SuperClassBase) CloseLibrary((APTR) SuperClassBase);
  133.  if(DataTypesBase)  CloseLibrary((APTR) DataTypesBase);
  134.  if(UtilityBase)    CloseLibrary((APTR) UtilityBase);
  135.  if(GfxBase)        CloseLibrary((APTR) GfxBase);
  136.  if(IntuitionBase)  CloseLibrary((APTR) IntuitionBase);
  137.  if(DOSBase)        CloseLibrary((APTR) DOSBase);
  138. }
  139.